﻿using LPY.LeHealth.DAL;
using LPY.LeHealth.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LPY.LeHealth.Service
{
    using AutoMapper;
    using AutoMapper.Execution;
    using AutoMapper.Configuration;
    using AutoMapper.Mappers;
    using LPY.LeHealth.DTO;
    public  class HospitalService
    {
        private HospitalDAL dal;

        public HospitalService()
        {
            dal = new HospitalDAL();
        }

        /// <summary>
        /// 医院列表（分页）
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public List<Hospital> GetHospitals(int pageIndex,int pageSize,out long totalSize)
        {
            var hos= dal.GetList(pageIndex, pageSize, out totalSize);
            var rtv= Mapper.Map<List<HospitalDTO>, List<Hospital>>(hos);
            return rtv;
        }

        /// <summary>
        /// 添加医院
        /// </summary>
        /// <param name="hos"></param>
        /// <returns></returns>
        public bool AddHospital(Hospital hos)
        {
            var hosDto = Mapper.Map<Hospital, HospitalDTO>(hos);
            hosDto.CreateTime = DateTime.Now;

            var rtv= dal.Add(hosDto);
            return rtv;
        }

        /// <summary>
        /// 根据ID获取医院信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Hospital GetHospitalById(int id)
        {
            var hos = dal.GetById(id);
            var rtv = Mapper.Map<Hospital>(hos);
            return rtv;
        }

        /// <summary>
        /// 获取所有医院
        /// </summary>
        /// <returns></returns>
        public List<Hospital> GetAllHospitall()
        {
           List<HospitalDTO> dtos= dal.GetAll();
           return Mapper.Map<List<Hospital>>(dtos);
        }

        /// <summary>
        /// 修改医院
        /// </summary>
        public bool UpdatePhysicalItem(Hospital physical)
        {
            var physicaldto = Mapper.Map<Hospital,HospitalDTO>(physical);
            var rtv = dal.Edit(physicaldto);
            return rtv;
        }

        /// <summary>
        /// 删除医院
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeletePhysicalItemById(int id)
        {
            return dal.DeletePhysicalItemById(id);
        }
    }
}
